package handle

import (
	"fmt"

	"github.com/kataras/iris/v12"
	"github.com/labstack/echo/v4"
)

type File struct {
}

func (r File) InitRoute(party *echo.Group) {
	p := party.Group("/file")
	p.POST("/upload", r.Upload())
	p.POST("/uploads", r.FormFiles())
	p.POST("/uploadFormFiles", r.UploadFormFiles())
	p.POST("/sendFile", r.SendFile())
}

const maxSize = 8 * iris.MB

func (r File) Upload() echo.HandlerFunc {
	return func(ctx echo.Context) error {
		file, err := ctx.FormFile("files")
		if err != nil {
			return err
		}
		fmt.Println(file.Filename)
		return nil
	}
}
func (r File) FormFiles() echo.HandlerFunc {
	return func(ctx echo.Context) error {
		files, err := ctx.MultipartForm()
		if err != nil {
			ctx.JSON(400, err)
			return err
		}
		for s, headers := range files.File {
			fmt.Println(s, headers)
			for i, header := range headers {
				fmt.Println(i, header.Header)
			}
		}
		for s, headers := range files.Value {
			fmt.Println(s, headers)
		}
		return nil
	}
}
func (r File) UploadFormFiles() echo.HandlerFunc {
	return func(ctx echo.Context) error {

		//ctx.File()
		return nil
	}
}
func (r File) SendFile() echo.HandlerFunc {
	return func(ctx echo.Context) error {
		return nil
	}
}
